package org.example.controller;

import org.example.domain.Book;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

@RestController
@RequestMapping("/books")
public class BookController {
    @PostMapping
    public String save(@RequestBody Book book) {
        System.out.println("book save --->" + book);
        return "{'module' : 'book save success'}";
    }

    @GetMapping
    public List<Book> getAll() {
        List<Book> list = new ArrayList<>();

        Book book1 = new Book();
        book1.setType("computer");
        book1.setName("SpringMVC入门");
        book1.setDescription("小试牛刀");

        Book book2 = new Book();
        book2.setType("computer");
        book2.setName("SpringMVC实战");
        book2.setDescription("一代宗师");

        Collections.addAll(list, book1, book2);
        return list;
    }
}
